//
//  HMVisitorTableViewController.swift
//  WeiBoXR
//
//  Created by acer on 16/9/21.
//  Copyright © 2016年 acer. All rights reserved.
//

import UIKit

class HMVisitorTableViewController: UITableViewController,HMVisitorViewDelegate {

//    var isLogin = false
    var isLogin: Bool = HMUserAccountViewModel.sharedUserAccountViewModel.isLogin
    var visitorView: HMVisitorView?
    override func loadView() {
        
        if isLogin {
            super.loadView()
        }else{
            visitorView = HMVisitorView()
            view = visitorView
            setupNavUI()
            visitorView?.loginDelegate = self
            visitorView?.loginClosure = { [weak self] in
                print("闭包调用")
                self?.loginRequestOperation()
            }
        }
    }
    
    private func setupNavUI() {

        navigationItem.leftBarButtonItem = UIBarButtonItem(title: "登陆", target: self, action: #selector(loginBtnClick))
        navigationItem.rightBarButtonItem = UIBarButtonItem(title: "注册", target: self, action: #selector(loginBtnClick))
    }
    
    @objc private func loginBtnClick()  {
        
        print("xx")
    }
    override func viewDidLoad() {
        super.viewDidLoad()

        // Uncomment the following line to preserve selection between presentations
        // self.clearsSelectionOnViewWillAppear = false

        // Uncomment the following line to display an Edit button in the navigation bar for this view controller.
        // self.navigationItem.rightBarButtonItem = self.editButtonItem()
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }

    func didClickLoginBtn() {
        print("代理调用")
        loginRequestOperation()
    }
    private func loginRequestOperation() {
        
        let oatherVC = HMOAuthViewController()
        let nav = HMNavigationController(rootViewController: oatherVC)
        present(nav, animated: true, completion: nil)
    }
}
